package net.brucecooper.mindmap.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.PopupPanel;

public abstract class Action implements ClickHandler {
    public String icon;
    public String name;
    
    
    public Action(String name, String icon) {
        this.icon = icon;
        this.name = name;
    }
    
    public Button createButton() {
        ButtonWithTooltip newChildButton = new ButtonWithTooltip(name, icon);
        newChildButton.addClickHandler(this);
        return newChildButton;
    }
    
    public Anchor createMenuItem(final PopupPanel contextPopup) {
        Anchor a = new Anchor(IconManager.makeImgHTML(name, icon) + name, true);
        a.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                contextPopup.hide();
            }
        });
        a.addClickHandler(this);
        return a;
    }

}
